package com.ds.bpm.graph;

import com.ds.bpm.bpd.service.BPDService;
import com.ds.bpm.engine.BPMConstants;
import com.ds.bpm.engine.BPMException;
import com.ds.common.logging.Log;
import com.ds.common.logging.LogFactory;
import com.ds.config.ErrorResultModel;
import com.ds.config.ResultModel;
import com.ds.esb.config.EsbBeanAnnotation;
import com.ds.esd.bpm.view.Graph;
import com.ds.esd.bpm.view.GraphService;

@EsbBeanAnnotation(id = "GraphService", name = "流程视图服务", expressionArr = "GraphServiceImpl()", desc = "BPD服务")

public class GraphServiceImpl implements GraphService {

    private static final Log logger = LogFactory.getLog(BPMConstants.CONFIG_KEY, BPDService.class);


    @Override
    public ResultModel<Graph> getGraphInfo(String processVersionId) {
        ResultModel<Graph> result = new ResultModel<Graph>();
        try {
            GraphBuilder pagerBuilder = new GraphBuilder(processVersionId);
            Graph pager = pagerBuilder.build();
            result.setData(pager);
        } catch (BPMException e) {
            logger.error("", e);
            e.printStackTrace();
            result = new ErrorResultModel<Graph>();
            ((ErrorResultModel<Graph>) result).setErrcode(e.getErrorCode());
            ((ErrorResultModel<Graph>) result).setErrdes(e.getMessage());
        }
        return result;
    }


}
